<template>
	<view class="view">
		<view><input type="password" value="" v-model="jiu" placeholder="请输入原密码" style="height: 80rpx;margin-left: 20rpx;width: 600rpx;"/></view>
		<view><input type="password" value="" v-model="xin" placeholder="请输入新密码" style="height: 80rpx;margin-left: 20rpx;width: 600rpx;"/></view>
		<view><input type="password" value="" v-model="xin1" placeholder="请确认新密码" style="height: 80rpx;margin-left: 20rpx;width: 600rpx;"/></view>
		<u-button type="primary" style="margin-top: 40rpx;" @click="xgmm">修改密码</u-button>
	</view>
</template>

<script>
	import * as api from '@/api/api.js'
	export default{
	data() {
		return{
			jiu:'',
			xin:'',
			xin1:'',
			arr:[]
		}
	},
	onLoad() {
		api.request({
			url: '/p/user/userInfo',
			method: 'GET',
		}).then(res =>{
			this.arr = res.data
			console.log(res.data)
		})
	},
	methods:{
		xgmm(){
			let ada
			console.log(this.jiu,this.xin,this.xin1)
			console.log(this.arr)
			console.log(ada)
			if(this.jiu == ""){
				uni.showToast({
					title: "旧密码不能为空",
					icon: "none"
				})
			}else if(this.xin == ""){
				uni.showToast({
					title: "新密码不能为空",
					icon: "none"
				})
			}else if(this.xin != this.xin1){
				uni.showToast({
					title: "两次密码不一致",
					icon: "none"
				})
			}else{
				ada = {
					jiu:this.jiu,
					xin:this.xin,
					sjh:this.arr.userMobile
				}
				console.log(ada)
				api.request({
					url: '/user/updatePwd',
					data:{
					loginPassword:ada.jiu,
					password:ada.xin,
					userId:'wxId',
					userMobile:ada.sjh,
					},
					method: 'PUT',
				}).then(res=>{
					console.log(res)
					if(res.statusCode == 200){
						console.log(res)
						this.pic = res.data.pic
						uni.showToast({
							title: "密码修改成功",
							icon: "success"
						})
						setTimeout(() => {
						uni.switchTab({
						   url: "/pages/user/user"
						})
						},500)
					}else{
						uni.showToast({
							title: "原密码不正确",
							icon: "none"
						})
					}
				})
			}
			
		},
	},
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #242329;
	}
	.view{
		width: 90%;
		margin: 0 auto;
	}
	.view>view{
		margin-top: 20rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		height: 80rpx;
	}
</style>
